package com.example.service;

import com.example.entity.PostCategory;
import com.example.entity.PostComments;
import com.example.mapper.PostCommentsMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
帖子内容业务处理
 */
@Service
public class PostCommentsService {

    @Resource
    private PostCommentsMapper postCommentsMapper;

    public void add(PostComments postComments) {
        postCommentsMapper.insert(postComments);
    }

    public void deleteById(Integer id) {
        postCommentsMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(PostComments postComments) {
        postCommentsMapper.updateById(postComments);
    }

    public PostComments selectById(Integer id) {
        return postCommentsMapper.selectById(id);
    }

    public List<PostComments> selectAll(PostComments postComments) {
        return postCommentsMapper.selectAll(postComments);
    }

    public PageInfo<PostComments> selectPage(PostComments postComments, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<PostComments> postCommentsList = postCommentsMapper.selectAll(postComments);
        return PageInfo.of(postCommentsList);
    }
}
